﻿using System;
using System.Configuration;
using System.Web.Configuration;

namespace BBI.Infrastructure.Config
{
    public class ArticlesElement : ConfigurationElement
    {

        [ConfigurationProperty("connectionStringName")]
        public string ConnectionStringName
        {
            get { return (string)this["connectionStringName"]; }
            set { this["ConnectionStringName"] = value; }
        }

        public string ConnectionString
        {
            get
            {
                string connStringName = null;
                if (string.IsNullOrEmpty(this.ConnectionStringName))
                {
                    connStringName = Globals.Settings.DefaultConnectionStringName;
                }
                else
                {
                    connStringName = this.ConnectionStringName;
                }
                return WebConfigurationManager.ConnectionStrings[connStringName].ConnectionString;
            }
        }

        [Obsolete("No longer a factor with the Entity Framework.")]
        public string ProviderType
        {
            get { return (string)this["providerType"]; }
            set { this["providerType"] = value; }
        }

        [ConfigurationProperty("ratingLockInterval", DefaultValue = "15")]
        public int RatingLockInterval
        {
            get { return (int)this["ratingLockInterval"]; }
            set { this["ratingLockInterval"] = value; }
        }

        [ConfigurationProperty("pageSize", DefaultValue = "10")]
        public int PageSize
        {
            get { return (int)this["pageSize"]; }
            set { this["pageSize"] = value; }
        }

        [ConfigurationProperty("rssItems", DefaultValue = "5")]
        public int RssItems
        {
            get { return (int)this["rssItems"]; }
            set { this["rssItems"] = value; }
        }

        [ConfigurationProperty("enableCaching", DefaultValue = "true")]
        public bool EnableCaching
        {
            get { return (bool)this["enableCaching"]; }
            set { this["enableCaching"] = value; }
        }

        [ConfigurationProperty("cacheDuration")]
        public int CacheDuration
        {
            get
            {
                int duration = (int)this["cacheDuration"];
                if (duration > 0)
                {
                    return duration;
                }
                else
                {
                    return Globals.Settings.DefaultCacheDuration;
                }
            }
            set { this["cacheDuration"] = value; }
        }

        [ConfigurationProperty("urlIndicator")]
        public string URLIndicator
        {
            get
            {
                string lurlIndicator = this["urlIndicator"].ToString();
                if (string.IsNullOrEmpty(lurlIndicator))
                {
                    lurlIndicator = "Article";
                }
                return lurlIndicator;
            }
            set { this["urlIndicator"] = value; }
        }

        [ConfigurationProperty("categoryUrlIndicator")]
        public string CategoryUrlIndicator
        {
            get
            {
                string lurlIndicator = this["categoryUrlIndicator"].ToString();
                if (string.IsNullOrEmpty(lurlIndicator))
                {
                    lurlIndicator = "Category";
                }
                return lurlIndicator;
            }
            set { this["categoryUrlIndicator"] = value; }
        }

        [ConfigurationProperty("articleThumbnail", DefaultValue = "/Content/Admin/img/No_image_200x200.jpg")]
        public string ArticleThumbnail
        {
            get
            {
                string articleThumbnail = this["articleThumbnail"].ToString();
                if (string.IsNullOrEmpty(articleThumbnail))
                {
                    articleThumbnail = "/Content/Admin/img/No_image_200x200.jpg";
                }
                return articleThumbnail;
            }
            set { this["articleThumbnail"] = value; }
        }

 

      

    }
}
